package  cn.stylefeng.guns.modular.business.service.impl;

import cn.stylefeng.guns.modular.business.entity.SampleStorageLocation;
import cn.stylefeng.guns.modular.business.mapper.SampleStorageLocationMapper;
import cn.stylefeng.guns.modular.business.reqeust.SampleStorageLocationRequest;
import cn.stylefeng.guns.modular.business.service.ISampleStorageLocationService;
import cn.stylefeng.roses.kernel.db.api.pojo.page.PageResult;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import cn.stylefeng.roses.kernel.db.api.factory.PageFactory;
import cn.stylefeng.roses.kernel.db.api.factory.PageResultFactory;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import org.springframework.stereotype.Service;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author generator
 * @since 2024-07-12
 */
@Service
public class SampleStorageLocationServiceImpl extends ServiceImpl<SampleStorageLocationMapper, SampleStorageLocation> implements ISampleStorageLocationService {

    @Override
    public PageResult<SampleStorageLocation> findPage(SampleStorageLocationRequest sampleStorageLocationRequest) {
        LambdaQueryWrapper<SampleStorageLocation> wrapper = createWrapper(sampleStorageLocationRequest);
        Page<SampleStorageLocation> page = this.page(PageFactory.defaultPage(), wrapper);
        return PageResultFactory.createPageResult(page);
    }

    private LambdaQueryWrapper<SampleStorageLocation> createWrapper(SampleStorageLocationRequest sampleStorageLocationRequest) {
        LambdaQueryWrapper<SampleStorageLocation> queryWrapper = new LambdaQueryWrapper<>();
        // 查询未删除状态的
        //queryWrapper.eq(SampleStorageLocation::getDelFlag, SysEnum.NO.getCode());

        // SQL条件拼接
        //queryWrapper.eq(ObjectUtils.isNotEmpty(sampleStorageLocationRequest.getId()), SampleStorageLocation::getId, sampleStorageLocationRequest.getId());

        // 根据创建时间降序排列
        //queryWrapper.orderByDesc(SampleStorageLocation::getCreateTime);
        return queryWrapper;
    }
}
